<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <title>AJ MCP SDK/MCP Client SDK Usage</title>
        <meta name="description" content="A lightweight Java 8 Model Context Protocol (MCP) SDK. MCP Client SDK Usage"/>
        <meta name="keywords" content="mcp, mcp sdk, java mcp, mcp client, mcp server, java8 mcp, usage"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link rel="stylesheet" href="/asset/style/main.css"/>
        <link rel="icon" type="image/png" href="/asset/favicon.ico"/>
        <script src="/asset/common.js"></script>
    </head>
    <body>
        <nav>
            <div>
                <div class="links">
                    <a href="/">🏠 Home</a>
                    | ⚙️ Source:
                    <a target="_blank" href="https://github.com/lightweight-component/aj-mcp">Github</a>/<a target="_blank" href="https://gitcode.com/lightweight-component/aj-mcp">Gitcode</a>
                    |
                    <a href="/cn">Chinese Version</a>
                </div>
                <h1>AJ MCP SDK</h1>
                <h3>User Manual</h3>
            </div>
        </nav>
        <div>
            <menu>
                
                <ul>
                    <li class="selected">
                        <a href="/">Home</a>
                    </li>
                    <li>
                        <a href="/architecture/index">Architecture</a>
                    </li>
                </ul>
                <h3>MCP Client SDK</h3>
                <ul>
                    <li>
                        <a href="/client/setup-client">Client SDK Setup</a>
                    </li>
                    <li>
                       <a href="/client/initialization">Initialization</a>
                    </li>
                    <li>
                       <a href="/client/resource">Resources Usage</a>
                    </li>
                     <li>
                       <a href="/client/prompt">Prompts Usage</a>
                    </li>
                     <li>
                       <a href="/client/tool">Tools Usage</a>
                    </li>
                </ul>
                <h3>MCP Server SDK</h3>
                <ul>
                      <li>
                           <a href="/server/usage-server">Server SDK Usage</a>
                      </li>
                      <li>
                           <a href="/server/res-server">Resources Usage</a>
                      </li>
                      <li>
                           <a href="/server/pro-server">Prompts Usage</a>
                      </li>
                      <li>
                             <a href="/server/tool-server">Tools Usage</a>
                       </li>
                      <li>
                         <a href="/server/sample">Integration Samples</a>
                      </li>
                </ul>

                <h3>Misc</h3>
                <ul>
                    <li><a href="/misc/contact">Contact</a></li>
                    
                </ul>
            </menu>
            <article>
                <h1>MCP Client SDK Usage</h1>
<h2>Install Dependency</h2>
<p>We’ll need the AJ MCP SDK for making API requests. Install it with Maven:</p>
<pre><code class="language-xml">
&lt;dependency&gt;
    &lt;groupId&gt;com.ajaxjs&lt;/groupId&gt;
    &lt;artifactId&gt;aj-mcp-server&lt;/artifactId&gt;
    &lt;version&gt;1.1&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>
<p>We can find the latest version:
<a href="https://central.sonatype.com/artifact/com.ajaxjs/aj-mcp-client"><img src="https://img.shields.io/maven-central/v/com.ajaxjs/aj-mcp-client?label=Latest%20Release" alt="Maven Central"></a></p>
<h2>Setup the Transport</h2>
<p>First, we need to create the transport. There are two types of transport you can choose from for your application, depending on the type of your MCP
server.</p>
<h3>Stdio Transport</h3>
<p>'Stdio' stands for Standard Input/Output, by using command line to interact between the programme and human in short. But here is between the MCP
Client
and the MCP Server. Usually, we use stdio for the local application, such as a <code>*.exe</code> programme or a Java Jar programme, and so on.</p>
<pre><code class="language-java">// The MCP server is a Java programme, runs on stdio.
McpTransport transport = StdioTransport.builder()
    .command(Arrays.asList(&quot;java&quot;, &quot;-jar&quot;, &quot;C:\\app\\my-app-jar-with-dependencies.jar&quot;))
    .logEvents(true)
    .build();
</code></pre>
<p>Let's take a look at a <code>.exe</code> programme as an example:</p>
<pre><code class="language-java">// The MCP server is an executable programme, runs on stdio.
McpTransport transport = StdioTransport.builder()
.command(&quot;C:\\app\\my-app.exe&quot;, &quot;-token&quot;, &quot;dd4df2sx32ds&quot;))
.logEvents(true)
.build();
</code></pre>
<p>If you want to check out the fully logs of the client, you can set <code>logEvents</code> to <code>true</code>. This is good for learning the MCP protocol, to get more
about the JSON messages of this protocol.</p>
<h2>Configure SDK</h2>
<table>
<thead>
<tr>
<th>Property</th>
<th>Note</th>
<th>Type of value</th>
<th>Example of value</th>
</tr>
</thead>
<tbody>
<tr>
<td>clientName</td>
<td>Sets the name that the client will use to identify itself to the MCP server in the initialization message.</td>
<td>String</td>
<td>myapp/foo-app</td>
</tr>
<tr>
<td>clientVersion</td>
<td>Sets the version string that the client will use to identify itself to the MCP server in the initialization message. The default value is &quot;1.0&quot;.</td>
<td>String</td>
<td>1.0/2.1.2</td>
</tr>
<tr>
<td>protocolVersion</td>
<td>Sets the protocol version that the client will advertise in the initialization message. The default value right now is &quot;2024-11-05&quot;, but will change over time in later versions.</td>
<td>String</td>
<td>2024-11-05</td>
</tr>
<tr>
<td>requestTimeout</td>
<td>Sets the timeout for tool execution. This value applies to each tool execution individually. The default value is 60 seconds. A value of zero means no timeout.</td>
<td>Duration</td>
<td><code>Duration.ofSeconds(60)</code></td>
</tr>
</tbody>
</table>
<style>
table th:nth-child(2) {
 min-width: 400px;
}
table th:nth-child(3), table td:nth-child(3) {
 min-width: 120px!important;
 width: 120px;
}

table td:nth-child(2) {
 text-align: left;
}
</style>

            </article>
        </div>
        <footer>
            AJ MCP SDK, a part of
            <a href="https://framework.ajaxjs.com" target="_blank">AJ-Framework</a>
            open source. Mail:frank@ajaxjs.com, visit
            <a href="https://blog.csdn.net/zhangxin09" target="_blank">my blog(In Chinese)</a>. <br/> <br/> Copyright © 2025 Frank Cheung. All rights reserved.
        </footer>
    </body>
</html>